package cn.remexs.flink.udf.geo;

import cn.remexs.flink.udf.GeoUtils;
import org.apache.flink.table.functions.ScalarFunction;
import org.locationtech.jts.geom.Geometry;


public class CentroidWkt extends ScalarFunction {
    public CentroidWkt() {
    }

    public String eval(String wkt) {
        try {
            if (null == wkt) return null;
            Geometry geometry = GeoUtils.wktToGeometry(wkt);
            if (null == geometry) return null;
            return geometry.getCentroid().toText();
        } catch (Exception e) {
            return null;
        }
    }
}